home *** CD-ROM | disk | FTP | other *** search
- /*
- * The VirtuaLight Binary Format API (VIBsdk for Visual C++)
- * Written by Stephane Marty
- * Version 1.0.4 (October 2002)
- */
-
- #if !defined(_VIB_SDK)
- #define _VIB_SDK
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <io.h>
- #include <math.h>
- #if defined(__BORLANDC__)
- #include <string.h>
- #endif
-
- /*
- * Basic defs
- */
- typedef float viFLT;
-
- // note: to restrict the size of files written out
- // to disk, "float" is used instead of "double"
- typedef float viDBL;
-
- typedef int viINT;
-
- typedef unsigned char viBYTE;
-
- typedef viDBL viMATRIX[4][4];
-
- typedef struct vec { viDBL x, y, z; } viVECTOR;
-
- typedef struct vec4p { viDBL x, y, z, H; } viVECTOR4p;
-
- typedef struct col { viFLT r, g, b; } viCOLOR;
-
- typedef struct cola { viBYTE r, g, b, a; } viCOLORBYTE;
-
- typedef struct uv { viFLT u, v; } viUV;
-
- typedef struct shear { viDBL yx, zx, xy, zy, xz, yz; } viSHEAR;
-
- typedef struct trans {
- viVECTOR Scale;
- viVECTOR Rotate;
- viVECTOR Translate;
- } viTRANSFORM;
-
- typedef struct _iobuf viFILE;
-
- /*
- * Camera
- */
- typedef struct form { // image format
- viINT X;
- viINT Y;
- } viSform;
-
- typedef struct clip { // clipping
- viDBL Near;
- viDBL Far;
- } viSclip;
-
- typedef struct dof { // depth of field
- viDBL Aperture;
- viDBL Distance;
- viINT Samples;
- } viSdof;
-
- typedef struct exp { // film exposure
- viDBL Gain;
- viDBL Gamma;
- } viSexp;
-
- typedef struct pfilt { // pixel filter
- viDBL xWidth;
- viDBL yWidth;
- viBYTE Function;
- } viSpfilt;
-
- typedef struct cam { // Main Camera structure
- viVECTOR Location;
- viVECTOR LookAt;
- viVECTOR UpAxis;
- viDBL FieldOfView;
- viSform Format;
- viDBL FrameAspectRatio;
- viSclip Clipping;
- viSdof DepthOfField;
- viSexp Exposure;
- viINT Antialiasing;
- viINT SuperAntialiasing;
- viINT Undersampling;
- viBYTE LensModel;
- viSpfilt PixelFilter;
- viTRANSFORM Transform;
- } viCAMERA;
-
- /*
- * Global options
- */
- typedef struct gc { // gamma correction
- viDBL D;
- viDBL DG;
- } viSgc;
-
- typedef struct irr { // monte carlo irradiance
- viINT BounceLevel;
- viDBL MaxError;
- viINT Samples;
- viBYTE Distribution;
- viINT PhotonsSamples;
- viINT PhotonsMax;
- viDBL BlendingArea;
- viDBL MaxDistance;
- } viSirr;
-
- typedef struct pgr { // photons gather range
- viINT Min;
- viINT Max;
- } viSpgr;
-
- typedef struct pacc { // photons accelerator
- viDBL Caustics;
- viDBL Media;
- viDBL Irradiance;
- } viSpac;
-
- typedef struct opt { // Main Options structure
- viDBL AdaptiveThreshold;
- viINT AdaptiveDepth;
- viDBL ShadowBias;
- viINT BitsPerPixel;
- char OutputTo[64];
- viSgc GammaCorrection;
- viDBL SunGlow;
- viBYTE ParallelSunRays;
- viSirr Irradiance;
- char LoadIrradianceCache[64];
- char SaveIrradianceCache[64];
- char LoadPhotonMap[64];
- char SavePhotonMap[64];
- viSpgr PhotonsGatherRange;
- viSpac PhotonsAccelerator;
- viBYTE MaxRayLevel;
- viBYTE MaxBlurLevel;
- viINT SoftShadowSamples;
- viINT MaxBlurSamples;
- viDBL HenyeyGreenstein;
- viINT Z_Size;
- } viOPTIONS;
-
- /*
- * Independant features
- */
- typedef struct fog { // distant fog
- viDBL distance;
- viDBL coeff;
- viCOLOR color;
- } viSfog;
-
- typedef struct gfog { // ground fog
- viDBL distance;
- viDBL height;
- viCOLOR color;
- } viSgfog;
-
- typedef struct phot { // photons
- viINT count;
- viDBL density;
- viINT media;
- viINT volume;
- } viSphot;
-
- typedef struct med { // media
- viINT sm;
- viINT sa;
- viDBL de;
- viDBL sc;
- viDBL filter;
- viINT aalias;
- viCOLOR color;
- } viSmed;
-
- typedef struct gen { // Main General structure
- viCOLOR Background;
- char BackgroundExpression[32];
- viSfog Fog;
- viSgfog GroundFog;
- viINT ComputeIrradiance;
- viSphot Photons;
- viSmed Media;
- } viGENERAL;
-
- /*
- * Lights
- */
- typedef struct p_light { // point light
- viVECTOR Position;
- viCOLOR Intensity;
- viBYTE Decay;
- viDBL Range;
- viDBL Glow;
- viBYTE LightingAttributes;
- viBYTE MediaInteraction;
- } viPOINT_LIGHT;
-
- typedef struct s_light { // spotlight
- viVECTOR Position;
- viVECTOR PointAt;
- viDBL Radius;
- viDBL Falloff;
- viDBL Tightness;
- viCOLOR Intensity;
- viBYTE Decay;
- viDBL Range;
- viDBL Bulb;
- viBYTE LightingAttributes;
- viBYTE MediaInteraction;
- } viSPOT_LIGHT;
-
- typedef struct d_light { // directional light
- viVECTOR Direction;
- viCOLOR Intensity;
- viBYTE LightingAttributes;
- } viDIRECTIONAL_LIGHT;
-
- typedef struct bh { // black hole
- viVECTOR Location;
- viDBL Density;
- viCOLOR Intensity;
- } viBLACK_HOLE;
-
- typedef struct bulb { // spherical light bulb
- viVECTOR Location;
- viDBL Radius;
- } viSbulb;
-
- typedef struct sa_light { // spherical area light
- viSbulb Bulb;
- viCOLOR Intensity;
- viBYTE Decay;
- viDBL Range;
- viDBL Glow;
- viBYTE LightingAttributes;
- viBYTE MediaInteraction;
- viTRANSFORM Transform;
- } viSPH_AREA_LIGHT;
-
- typedef struct plan { // plane light
- viINT Row;
- viINT Col;
- viDBL Jitter;
- viINT Level;
- } viSplan;
-
- typedef struct fa_light { // flat polygonal area light
- viSplan Plane;
- viCOLOR Intensity;
- viBYTE Decay;
- viDBL Range;
- viBYTE LightingAttributes;
- viTRANSFORM Transform;
- } viFLAT_AREA_LIGHT;
-
- typedef struct skl { // skylight
- viBYTE Enabled;
- viINT samples;
- viCOLOR color;
- char ColorExpression[32];
- viDBL brightness;
- } viSskl;
-
- typedef struct sul { // sunlight
- viBYTE Enabled;
- viINT hours;
- viINT minutes;
- viINT samples;
- viDBL brightness;
- viCOLOR color;
- viVECTOR Rotate;
- } viSsul;
-
- typedef struct skydome { // Main Skydome structure
- viSskl SkyLight;
- viSsul SunLight;
- } viSKY_DOME;
-
- typedef struct rb { // render bound
- viDBL umin;
- viDBL vmin;
- viDBL umax;
- viDBL vmax;
- } viSrb;
-
- typedef struct shpsub { // shape subdivisions
- viINT u;
- viINT v;
- viINT w;
- } viSshpsubd;
-
- typedef struct shpmod { // Main Shape Modifiers structure
- viSrb RenderBound;
- viINT ShadingAttributes;
- viSshpsubd ShapeSubdivisions;
- char DisplacementMapping[32];
- } viSHAPE_MODIFIERS;
-
- /*
- * Shapes
- */
- typedef struct pch { // smooth triangular patch
- viVECTOR v1;
- viVECTOR n1;
- viVECTOR v2;
- viVECTOR n2;
- viVECTOR v3;
- viVECTOR n3;
- } viPATCH;
-
- typedef struct pchuv { // smooth triangular patch with uv
- viVECTOR v1;
- viVECTOR n1;
- viUV uv1;
- viVECTOR v2;
- viVECTOR n2;
- viUV uv2;
- viVECTOR v3;
- viVECTOR n3;
- viUV uv3;
- } viPATCH_UV;
-
- typedef struct sph { // sphere
- viVECTOR center;
- viDBL radius;
- } viSPHERE;
-
- typedef struct con { // cone
- viVECTOR base;
- viDBL baserad;
- viVECTOR apex;
- viDBL apexrad;
- } viCONE;
-
- typedef struct cyl { // cylinder
- viVECTOR bottom;
- viVECTOR top;
- viDBL radius;
- } viCYLINDER;
-
- typedef struct dis { // disk
- viVECTOR center;
- viVECTOR normal;
- viDBL radius;
- } viDISK;
-
- typedef struct rin { // ring
- viVECTOR center;
- viVECTOR normal;
- viDBL majrad;
- viDBL minrad;
- } viRING;
-
- typedef struct tor { // torus
- viVECTOR center;
- viVECTOR dir;
- viDBL majrad;
- viDBL minrad;
- } viTORUS;
-
- typedef struct box { // box
- viVECTOR corner1;
- viVECTOR corner2;
- } viBOX;
-
- typedef struct sup { // superquadric
- viDBL h;
- viDBL w;
- } viSUPERQ;
-
- typedef struct pol { // polygon
- viBYTE vertices;
- viVECTOR vertex[32];
- } viPOLYGON;
-
- typedef struct nbs { // nurbs
- viINT nu;
- viINT uorder;
- viDBL *uknot;
- viINT nv;
- viINT vorder;
- viDBL *vknot;
- viVECTOR4p **cpoints;
- viINT nuknots, nvknots;
- } viNURBS;
-
- typedef struct bez { // bezier patch
- viBYTE basis;
- viINT ustep;
- viINT vstep;
- viVECTOR vertices[16];
- } viBEZIER;
-
- typedef struct parab { // parabola
- viVECTOR base;
- viVECTOR top;
- viDBL radius;
- } viPARABOLOID;
-
- typedef struct fld { // blobby's component
- viBYTE type;
- viVECTOR sc_cb_pn;
- viVECTOR top;
- viDBL dist;
- viDBL radius;
- viDBL strength;
- } viFIELD;
-
- typedef struct blob { // blobby
- viBYTE solver;
- viINT fields;
- viDBL threshold;
- viFIELD *components;
- } viBLOBBY;
-
- /*
- * Misc defs
- */
- #define VLIGHT_BIG (1.0e+6)
- #define VLIGHT_SMALL (1.0e-3)
- #define VLIGHT_EPSILON (1.0e-8)
-
- #ifndef FALSE
- #define FALSE 0
- #endif
- #ifndef TRUE
- #define TRUE 1
- #endif
- #ifndef M_PI
- #define M_PI (3.1415926535897932384626)
- #endif
-
- // Irradiance distribution methods
- #define DISTRIB_REGULAR 0x01
- #define DISTRIB_GRID 0x02
- #define DISTRIB_HAMMERSLEY 0x03
- #define DISTRIB_ADAPTIVE_U 0x04
- #define DISTRIB_RANDOM 0x05
- #define DISTRIB_NROOKS 0x06
-
- // Light source decay rates
- #define DECAY_LINEAR 0x01
- #define DECAY_QUADRATIC 0x02
- #define DECAY_CUBIC 0x03
-
- // Lighting attributes
- #define LIGHT_ATTRIB_NOTHING 0x00
- #define LIGHT_ATTRIB_SHADOW 0x01
- #define LIGHT_ATTRIB_SPECULAR 0x02
- #define LIGHT_ATTRIB_ONESIDED 0x04
- #define LIGHT_ATTRIB_AUTOORIENT 0x08
-
- // Camera lenses
- #define LENS_PERSPECTIVE 0xf0
- #define LENS_ORTHOGRAPHIC 0xf1
- #define LENS_WIDE_ANGLE 0xf2
- #define LENS_FISHEYE 0xf3
- #define LENS_PANORAMIC 0xf4
- #define LENS_OMNIMAX 0xf5
-
- // Participating media scattering models
- #define ISOTROPIC_SCATTERING 0x01
- #define RAYLEIGH_SCATTERING 0x02
- #define MIE_SCATTERING 0x03
- #define HENYEY_SCATTERING 0x04
-
- // Blobby field types
- #define FIELD_SPHERE 0x01
- #define FIELD_CYLINDER 0x02
- #define FIELD_PLANE 0x03
-
- // Bicubic patch basis
- #define BEZIER_MATRIX 0x01
- #define BSPLINE_MATRIX 0x02
- #define CATMULLROM_MATRIX 0x03
- #define HERMITE_MATRIX 0x04
-
- // Root solvers for blobby
- #define FERRARI_SOLVER 0x01
- #define VIETA_SOLVER 0x02
- #define STURM_SOLVER 0x03
-
- // Pixel filter types
- #define BOXfilter 0x01
- #define TRIANGLEfilter 0x02
- #define CATMULLROMfilter 0x03
- #define GAUSSIANfilter 0x04
- #define SINCfilter 0x05
- #define DISKfilter 0x06
- #define BESSELfilter 0x07
-
- // Variable/data initialization macros
- #define viSetInt(a, b) a = (viINT)(b)
- #define viSetDbl(a, b) a = (viDBL)(b)
- #define viSetFlt(a, b) a = (viFLT)(b)
- #define viSetByte(a, b) a = (viBYTE)(b)
- #define viSetString(s1,s2) {memset(s1,0,sizeof(s1));memcpy((s1),(s2),sizeof(s1));}
- #define viSetVector(v, x, y, z) viMakeVector(v, (viDBL)(x), (viDBL)(y), (viDBL)(z))
- #define viSetControlPoint(v, x, y, z) viMakeVector4p(v, (viDBL)(x), (viDBL)(y), (viDBL)(z), 0)
- #define viSetControlPointR(v, x, y, z, h) viMakeVector4p(v, (viDBL)(x), (viDBL)(y), (viDBL)(z), (viDBL)(h))
- #define viSetColor(c, r, g, b) viMakeColor(c, (viFLT)(r), (viFLT)(g), (viFLT)(b))
- #define viSetShear(s, yx, zx, xy, zy, xz, yz) viMakeShear(s, (viDBL)(yx), (viDBL)(zx), (viDBL)(xy), (viDBL)(zy), (viDBL)(xz), (viDBL)(yz))
-
- /*
- * viVECTOR macro definitions
- */
- #define viCopyVector(v1,v2) memcpy((v1),(v2),sizeof(viVECTOR))
- #define viVecAdd(a, b, c) {(a).x=(b).x+(c).x;(a).y=(b).y+(c).y;(a).z=(b).z+(c).z;}
- #define viVecSubstract(a, b, c) {(a).x=(b).x-(c).x;(a).y=(b).y-(c).y;(a).z=(b).z-(c).z;}
- #define viVecDivide(a, b, c) {(a).x=(b).x/(c).x;(a).y=(b).y/(c).y;(a).z=(b).z/(c).z;}
- #define viVecScale(a, b, k) {(a).x=(b).x*(k);(a).y=(b).y*(k);(a).z=(b).z*(k);}
- #define viVecDot(a, b, c) {a=(b).x*(c).x+(b).y*(c).y+(b).z*(c).z;}
- #define viVecCross(a,b,c) {(a).x=(b).y*(c).z-(b).z*(c).y; \
- (a).y=(b).z*(c).x-(b).x*(c).z; \
- (a).z=(b).x*(c).y-(b).y*(c).x;}
- #define viVecLength(a, b) {a=sqrt((b).x*(b).x+(b).y*(b).y+(b).z*(b).z);}
- #define viVecDistance(a, b, c) {viVECTOR vtmp; viVecSubstract(vtmp, b, c); viVecLength(a, vtmp);}
- #define viVecNormalize(a) {viDBL dtmp=(viDBL)(1.0/sqrt((a).x*(a).x+(a).y*(a).y+(a).z*(a).z));(a).x*=dtmp;(a).y*=dtmp;(a).z*=dtmp;}
- #define viVecHalf(a, b, c) {(a).x=0.5*((b).x+(c).x);(a).y=0.5*((b).y+(c).y);(a).z=0.5*((b).z+(c).z);}
-
- #if defined(__cplusplus)
- extern "C" {
- #endif
-
- /*
- * Protos
- */
- extern viVECTOR *viMakeVector(viVECTOR *, viDBL, viDBL, viDBL);
- extern viVECTOR4p *viMakeVector4p(viVECTOR4p *, viDBL, viDBL, viDBL, viDBL);
- extern viCOLOR *viMakeColor(viCOLOR *, viFLT, viFLT, viFLT);
- extern viMATRIX *viMatrixIdentity(viMATRIX *);
- extern viSHEAR *viMakeShear(viSHEAR *, viDBL, viDBL, viDBL, viDBL, viDBL, viDBL);
-
- // ---- VIB ----
- extern viFILE *viNewBinaryVIB(char *);
- extern int viCloseBinaryVIB(viFILE *);
- /* Camera */
- extern viCAMERA *viNewCamera(void);
- extern void viDumpCamera(viCAMERA *, viFILE *);
-
- /* Options */
- extern viOPTIONS *viNewOptions(void);
- extern void viDumpOptions(viOPTIONS *, viFILE *);
-
- /* General */
- extern viGENERAL *viNewGeneral(void);
- extern void viDumpGeneral(viGENERAL *, viFILE *);
-
- /* Point light */
- extern viPOINT_LIGHT *viNewPointLight(void);
- extern void viDumpPointLight(viPOINT_LIGHT *, viFILE *);
-
- /* Spot light */
- extern viSPOT_LIGHT *viNewSpotLight(void);
- extern void viDumpSpotLight(viSPOT_LIGHT *, viFILE *);
-
- /* Directional light */
- extern viDIRECTIONAL_LIGHT *viNewDirectionalLight(void);
- extern void viDumpDirectionalLight(viDIRECTIONAL_LIGHT *, viFILE *);
-
- /* Black hole */
- extern viBLACK_HOLE *viNewBlackHole(void);
- extern void viDumpBlackHole(viBLACK_HOLE *, viFILE *);
-
- /* Spherical area light */
- extern viSPH_AREA_LIGHT *viNewSphAreaLight(void);
- extern void viDumpSphAreaLight(viSPH_AREA_LIGHT *, viFILE *);
-
- /* Polygonal area light */
- extern viFLAT_AREA_LIGHT *viNewFlatAreaLight(void);
- extern void viDumpFlatAreaLight(viFLAT_AREA_LIGHT *, viFILE *);
-
- /* Skylight & sunlight */
- extern viSKY_DOME *viNewSkyDome(void);
- extern void viDumpSkyDome(viSKY_DOME *, viFILE *);
-
- /* Shape modifers */
- extern viSHAPE_MODIFIERS *viNewShapeModifiers(void);
- extern void viDumpShapeModifiers(viSHAPE_MODIFIERS *, viFILE *);
-
- /* Object ID */
- extern void viDeclareNewObject(char *, viFILE *);
- extern void viEndObjectDeclaration(viFILE *);
- extern void viCallObject(char *, viFILE *);
- extern void viEndObjectCall(viFILE *);
- extern void viObjectShaderName(char *, viFILE *);
-
- /* Primitive ID */
- extern void viPrimitive(viFILE *);
- extern void viEndPrimitive(viFILE *);
- extern void viPrimitiveShaderName(char *, viFILE *);
-
- /* Object & Primitive transformation modifiers */
- extern void viDumpScale(viVECTOR *, viFILE *);
- extern void viDumpTranslate(viVECTOR *, viFILE *);
- extern void viDumpRotate(viVECTOR *, viFILE *);
- extern void viDumpTransform(viTRANSFORM *, viFILE *);
- extern void viDumpMatrix(viMATRIX *, viFILE *);
- extern void viDumpShear(viSHEAR *, viFILE *);
-
- /* Basic shapes for Object & Primitive */
- extern void viDumpPatch(viPATCH *, viFILE *);
- extern void viDumpPatchUV(viPATCH_UV *, viFILE *);
- extern void viDumpSphere(viSPHERE *, viFILE *);
- extern void viDumpCone(viCONE *, viFILE *);
- extern void viDumpCylinder(viCYLINDER *, viFILE *);
- extern void viDumpDisk(viDISK *, viFILE *);
- extern void viDumpRing(viRING *, viFILE *);
- extern void viDumpTorus(viTORUS *, viFILE *);
- extern void viDumpBox(viBOX *, viFILE *);
- extern void viDumpSuperQuadric(viSUPERQ *, viFILE *);
- extern void viDumpPolygon(viPOLYGON *, viFILE *);
- extern void viDumpBicubicPatch(viBEZIER *, viFILE *);
- extern void viDumpParaboloid(viPARABOLOID *, viFILE *);
- /* nurbs... */
- extern viNURBS *viNewNURBS(int, int, int, int);
- extern void viDumpNURBS(viNURBS *, viFILE *);
- extern int viDeleteNURBS(viNURBS *);
- /* blobby... */
- extern viBLOBBY *viNewBlobby(viDBL, int);
- extern void viDumpBlobby(viBLOBBY *, viFILE *);
- extern int viDeleteBlobby(viBLOBBY *);
- // ---- VIB ----
-
- // ---- MSH ----
- extern int viNewMSHFile(char *);
- extern int viCloseMSHFile(void);
-
- /* Mesh modifiers */
- extern viSHAPE_MODIFIERS *viNewMeshModifiers(void);
- extern void viAddMeshModifiers(viSHAPE_MODIFIERS *);
-
- /* Mesh ID */
- extern void viStartMeshDeclaration(char *);
- extern void viEndMeshDeclaration(void);
- extern void viCallMesh(char *);
- extern void viEndMesh(void);
- extern void viSetMeshShader(char *);
-
- /* Mesh transformation modifiers */
- extern void viScaleMesh(viVECTOR *);
- extern void viTranslateMesh(viVECTOR *);
- extern void viRotateMesh(viVECTOR *);
- extern void viTransformMesh(viTRANSFORM *);
- extern void viMatrixMesh(viMATRIX *);
- extern void viShearMesh(viSHEAR *);
-
- /* Mesh basic primitives */
- extern void viAddPatchToMesh(viPATCH *);
- extern void viAddPatchUVToMesh(viPATCH_UV *);
- extern void viAddPolygonToMesh(viPOLYGON *);
- extern void viAddSphereToMesh(viSPHERE *);
- extern void viAddConeToMesh(viCONE *);
- extern void viAddCylinderToMesh(viCYLINDER *);
- extern void viAddBoxToMesh(viBOX *);
- // ---- MSH ----
-
- #if defined(__cplusplus)
- }
- #endif
-
- #endif // _VIB_SDK